package com.scs.application.modules.msg.provider;

import com.scs.application.core.msg.domain.EmailMessage;
import com.scs.application.core.msg.domain.RawMessage;
import com.scs.application.core.msg.domain.SceneMessage;
import com.scs.application.modules.msg.entity.Template;
import com.scs.application.modules.upms.vo.UserVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 邮件消息处理
 */

@Component
@AllArgsConstructor
public class BuildEmailMessageProvider implements BuildMessageProvider<EmailMessage> {
    @Override
    public List<RawMessage> messagesBuild(List<UserVO> userInfoVOList, Template template, SceneMessage msg) {

        List<RawMessage> messageList = new ArrayList<>();
        userInfoVOList.stream().forEach((user) -> {
            EmailMessage emailMessage = new EmailMessage();
            emailMessage.setContent(getContent(template, msg, emailMessage.getMessageType()))
                    .setTitle(template.getTitle())
                    .setTo(user.getEmail());
            messageList.add(emailMessage);
        });
        return messageList;
    }

    @Override
    public boolean support(Class<? extends RawMessage> clz) {
        return (EmailMessage.class.isAssignableFrom(clz));
    }

}
